<template>
  <div class="count-panel">
    <div class="count-time">统计截止：{{ date }}</div>
    <div class="tabs">
      <div class="tab" v-for="item in tabs" :key="item.type">
        <div class="tab-title">
          {{ item.name }}
        </div>
        <div class="tab-count">
          <span class="count">
            {{ item?.conent?.count }}
          </span>
          <span class="unit">
            {{ item?.conent.unit }}
          </span>
        </div>
        <div class="tab-footer" v-if="item.type === 'modelJoinVo'">
          <div>
            <span class="name">启用</span>
            <span class="num"
              >{{ item?.conent?.startCount }}{{ item?.conent?.unit }}</span
            >
          </div>
          <div>
            <span class="name">禁用</span>
            <span class="num"
              >{{ item?.conent?.disableCount }}{{ item?.conent?.unit }}</span
            >
          </div>
        </div>
        <div class="tab-footer" v-if="switchTabs.includes(item.type)">
          <div>
            <span class="name">本年</span>
            <span class="num"
              >{{ item?.conent?.currentYearCount
              }}{{ item?.conent?.unit }}</span
            >
          </div>
          <div>
            <span class="name">历年</span>
            <span class="num"
              >{{ item?.conent?.previousYearsCount
              }}{{ item?.conent?.unit }}</span
            >
          </div>
        </div>
        <div class="tab-footer c-bar" v-if="item.type === 'followWarningVo'">
          <span>解除率</span>
          <div class="bar">
            <div
              class="bg"
              :style="{ width: item.conent.warningReleaseRate + '%' }"
            ></div>
          </div>
          <span>{{ item.conent.warningReleaseRate }}%</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCount } from '@/api/analyse.js'
export default {
  name: 'CountPanel',
  data() {
    return {
      date: '',
      switchTabs: ['allWarningCountVo', 'closeWarningVo'],
      tabs: [
        {
          type: 'modelJoinVo',
          name: '模型接入',
          conent: {}
        },
        {
          type: 'allWarningCountVo',
          name: '总预警数量',
          conent: {}
        },
        {
          type: 'followWarningVo',
          name: '解除预警/跟进数',
          conent: {}
        },
        {
          type: 'closeWarningVo',
          name: '关闭预警',
          conent: {}
        }
      ]
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.queryCount()
    },
    async queryCount() {
      const { data } = await getCount()
      this.date = data.date
      this.tabs = this.tabs.map((el) => {
        el.conent = data[el.type]
        return el
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.count-panel {
  .count-time {
    height: 28px;
    font-size: 18px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    color: #333333;
    line-height: 28px;
  }
  .tabs {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .tab {
      margin-right: 16px;
      flex: 1;
      // height: 130px;
      background: #ffffff;
      border: 1px solid #e6e6e6;
      border-radius: 2px;
      overflow: hidden;
      padding: 12px 16px;
      .tab-title {
        font-size: 14px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: 400;
        text-align: left;
        color: rgba(0, 0, 0, 0.45);
        line-height: 22px;
      }
      .tab-count {
        margin-top: 4px;

        .count {
          font-size: 30px;
          font-family: Helvetica Neue, Helvetica Neue-Regular;
          font-weight: 400;
          text-align: left;
          color: rgba(0, 0, 0, 0.85);
          // line-height: 38px;
        }
        .unit {
          margin-left: 4px;
          font-size: 14px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          text-align: left;
          color: rgba(0, 0, 0, 0.65);
          // line-height: 22px;
        }
      }
      .tab-footer {
        margin-top: 12px;
        padding-top: 8px;
        border-top: 1px solid #e8e8e8;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .name {
          font-size: 14px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          text-align: left;
          color: rgba(0, 0, 0, 0.65);
          line-height: 22px;
        }
        .num {
          margin-left: 6px;
          font-size: 14px;
          font-family: Helvetica Neue, Helvetica Neue-Regular;
          font-weight: 400;
          text-align: left;
          color: rgba(0, 0, 0, 0.85);
          line-height: 22px;
        }
      }
      .c-bar {
        .bar {
          width: 100%;
          flex: 1;
          height: 8px;
          background: #f0f2f5;
          border-radius: 1px;
          margin: 0 6px;
        }
        .bg {
          height: 100%;
          background: linear-gradient(116deg, #4eebe8, #74cbff 81%);
        }
      }
    }
    .tab:last-child {
      margin-right: 0;
    }
  }
}
</style>